<template>
  <div class='app-container'>
    <el-table :data="depList" style="width: 100%">
      <el-table-column prop="id" label="序号" width="180">
      </el-table-column>
      <el-table-column prop="name" label="部门名称" width="180">
      </el-table-column>
      <el-table-column prop="deptDesc" label="部门描述">
      </el-table-column>
      <el-table-column label="操作" width="100">
        <template slot-scope="scope">
          <el-button @click="handleUpdate(scope.row)" type="text" icon="el-icon-edit" size="small">编辑</el-button>
          <el-button @click="handleDelete(scope.row)" type="text" icon="el-icon-delete" size="small">删除</el-button>
        </template>
      </el-table-column>
    </el-table>


    <!-- 分配角色数据权限对话框 -->
    <el-dialog v-dialogDrag :title="title" :visible.sync="open" width="500px" append-to-body :close-on-click-modal='false' :close-on-press-escape='false'>
      <el-form :model="form" label-width="80px">
        <el-form-item label="所属类别:">
          <el-select v-model="form.type" placeholder="请选择">
            <el-option v-for="item in typeOptions" :key="item.roleId" :label="item.roleName" :value="item.roleId"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="类别序号">
          <el-input v-model="form.id" />
        </el-form-item>
        <el-form-item label="类别名称">
          <el-input v-model="form.name" />
        </el-form-item>
        <el-form-item label="类别描述">
          <el-input v-model="form.deptDesc" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="cancel">取 消</el-button>
        <el-button type="primary" @click="submitForm">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  departmentAdd,
  departmentEdit,
  getDep,
  delDep,
} from "@/api/extendApplication/complaints";
export default {
  data() {
    return {
      // 表格数据
      depList: [
        {
          id: 1,
          name: "办公室",
          deptDesc: "办公室办公室办公室办公室",
        },
        {
          id: 2,
          name: "办公室",
          deptDesc: "办公室办公室办公室办公室",
        },
        {
          id: 3,
          name: "办公室",
          deptDesc: "办公室办公室办公室办公室",
        },
        {
          id: 4,
          name: "办公室",
          deptDesc: "办公室办公室办公室办公室",
        },
        {
          id: 5,
          name: "办公室",
          deptDesc: "办公室办公室办公室办公室",
        },
      ],
      //对话框宽口
      open: false,
      //对话框标题
      title: null,
      //对话框中表单
      form: {},
      //所属类别
      typeOptions: [
        {
          roleName: "本部职能部",
          roleId: 1,
        },
      ],
      //depId
      depId: this.$route.query.depId,
    };
  },

  components: {},

  computed: {},

  mounted() {},

  watch: {
    value: {
      handler(val) {},
      deep: true,
      immediate: true,
    },
  },

  methods: {
    /** 查询用户列表 */
    getList() {
      this.loading = true;
      //日期范围
      listUser({ depId: this.depId }).then((response) => {
        this.userList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {};
      this.resetForm("form");
    },

    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      // this.getTreeselect();
      this.form = row;
      this.open = true;
      this.title = "添加用户";
      return;
      getUser().then((response) => {
        this.postOptions = response.data.posts;
        this.roleOptions = response.data.roles;
        this.form = row;
        this.open = true;
        this.title = "添加用户";
      });
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      // this.getTreeselect();
      this.form = row;
      const userId = row.userId || this.ids;
      this.form = row;
      this.open = true;
      this.title = "添加用户";
      return;
      getUser(userId).then((response) => {
        this.form = response.data.user;
        this.postOptions = response.data.posts;
        this.roleOptions = response.data.roles;
        this.form.postIds = response.data.postIds;
        this.form.roleIds = response.data.roleIds;
        this.open = true;
        this.title = "修改用户";
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const userIds = row.userId || this.ids;
      this.$confirm(
        '是否确认删除用户编号为"' + userIds + '"的数据项?',
        "警告",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }
      )
        .then(function () {
          return delUser(userIds);
        })
        .then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.userId != undefined) {
            departmentAdd(this.form).then((response) => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            departmentEdit(this.form).then((response) => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
  },
};
</script>

<style scoped lang='scss'>
</style>